﻿using System;
///using System.Collections.Generic;
using System.IO;
using System.Runtime.InteropServices;
//using System.Linq;
//using System.Text;
using System.Threading;
//using System.Threading.Tasks;
using System.Windows;
//using System.Windows.Controls;
//using System.Windows.Data;
//using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
//using System.Windows.Media.Imaging;
//using System.Windows.Shapes;
using System.Windows.Threading;

namespace QQ群成员获取
{
    /// <summary>
    /// 弹窗提示.xaml 的交互逻辑
    /// </summary>
    public partial class MessageBoxWindow : Window
    {
        //播放动画函数
        Storyboard story;
        private void 动画播放(string a)
        {
            story = (Storyboard)FindResource(a);
            BeginStoryboard(story);
        }
        public MessageBoxWindow(Color color,string strMsg)
        {
            InitializeComponent();
            icon.Foreground = new SolidColorBrush(color);
            模板一.Visibility = Visibility.Visible;
            labelTip.Text = strMsg;
            动画播放("打开");
            string path = Environment.GetEnvironmentVariable("systemdrive");
            if (File.Exists(path + @"\Windows\media\Windows Proximity Notification.wav") == false)
            {
                return;
            }
            PlaySound(path+@"\Windows\media\Windows Proximity Notification.wav", 0, 1);
        }
        [DllImport("winmm.dll")]
        public static extern bool PlaySound(String Filename, int Mod, int Flags);
        //字节转单位
        public static string GetFileSize(long size)
        {
            var num = 1024.00; //byte
            if (size < num) { return size + "B"; }    
            if (size < Math.Pow(num, 2)) { return (size / num).ToString("f2") + "KB"; }
            if (size < Math.Pow(num, 3)) { return (size / Math.Pow(num, 2)).ToString("f2") + "MB"; }
            if (size < Math.Pow(num, 4)) { return (size / Math.Pow(num, 3)).ToString("f2") + "GB"; }
            return (size / Math.Pow(num, 4)).ToString("f2") + "TB"; //T
        }

        private void Window_MouseDown(object sender, MouseButtonEventArgs e)
        {
            if (e.LeftButton == MouseButtonState.Pressed)
            {
                DragMove();
            }
        }

        private void 单文件_Click(object sender, RoutedEventArgs e)
        {
            exit();
        }

        private void 全文件_Click(object sender, RoutedEventArgs e)
        {
            exit();
        }

        private void 取消_Click(object sender, RoutedEventArgs e)
        {
            exit();
        }

        private void 确定_Click(object sender, RoutedEventArgs e)
        {
            exit();
        }

        private void exit()
        {
            动画播放("关闭");
            System.Timers.Timer t1 = new System.Timers.Timer(200);//实例化Timer类
            t1.Elapsed += new System.Timers.ElapsedEventHandler(theout1);//到达时间的时候执行事件
            t1.AutoReset = false;//设置是执行一次（false）还是一直执行(true)
            t1.Enabled = true;//是否执行System.Timers.Timer.Elapsed事件
        }
        public void theout1(object source, System.Timers.ElapsedEventArgs e)
        {
            new Thread(() =>
            {
                Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Normal,
                    new Action(() =>
                    {
                        Close();
                    }));
            }).Start();
        }
        //int a = 0;
        private void Window_Activated(object sender, EventArgs e)
        {
        }

        private void 关闭程序_Click(object sender, RoutedEventArgs e)
        {
            exit();
        }

        private void 知道了_Click(object sender, RoutedEventArgs e)
        {
            exit();
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            //Clipboard.SetText(问题.Text);
        }

        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            exit();
        }
    }
}
